package com.boco.webmaster.common.taglib;

import javax.servlet.http.*;
import javax.servlet.jsp.tagext.*;
import javax.servlet.jsp.JspException;
import java.io.*;

public class HeadTag extends TagSupport {
    private String title;
    public HeadTag() {
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getTitle() {
        return title;
    }

    public int doStartTag() throws JspException {
        StringBuffer header = new StringBuffer();

        try {
//            header.append("<head>\n");
//            header.append("<title>" + this.title + "</title>\n");
//            String contextPath = ((HttpServletRequest)this.pageContext.getRequest()).getContextPath();
//            header.append("<meta http-equiv=\"Content-Script-Type\" content=\"text/javascript\">");
//            header.append("<link rel=\"stylesheet\" href=\"" + contextPath +
//                          "/common/css/style.css\" type=\"text/css\">\n");
//            header.append("<link rel=\"stylesheet\" href=\"" + contextPath +
//                          "/common/css/default.css\" type=\"text/css\">\n");
//            header.append("</head>\n");

            header.append("<head>\n");
            header.append("<title>" + this.title + "</title>\n");
            String contextPath = ((HttpServletRequest)this.pageContext.getRequest()).getContextPath();
            HttpServletRequest request = (HttpServletRequest)this.pageContext.getRequest();
            String userTheme = com.boco.webmaster.security.validate.action.JspCheckUserHelper.getUserTheme(request);

            header.append("<meta http-equiv=\"Content-Script-Type\" content=\"text/javascript\">");
            header.append("<link rel=\"stylesheet\" href=\"" + contextPath +
                          "/common/css/"+userTheme+"/styleAll.css\" type=\"text/css\">\n");


            header.append("</head>\n");

            this.pageContext.getOut().write(header.toString());
        } catch (IOException ex) {
            ex.printStackTrace();
        } catch (Exception ex1){
            ex1.printStackTrace();
        }

        return Tag.SKIP_BODY;
    }
}

